<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>留学生管理系统</title> 
        <link rel="stylesheet" href="${path}/css/admin2.css">
        <style>
            #major-modal-1, #major-modal-2{
                margin: 12% auto;
                padding: 10px;
                width: 500px;
            }
        </style>
        <script>
            var _current_item = "#adminmajmanage";
        </script>
        <script type="text/javascript" src="${path}/js/jquery.min.js"></script>
    </head>
    <body>
        <!--header-->
        <div id="above-mask">
            <div class="fileupload pannel hide" id="fileupload-pannel">
                <div class="close-container">
                    <a class="close" onclick="hide('#above-mask, #mask, #fileupload-pannel');">×</a>
                </div>
                <form action="${path}/adminmajmanage/fileUpload" method="post" enctype="multipart/form-data" name="fileForm">
                    <div style="margin-top: 30px;"> 上传文件：（支持Excel 97-2003 工作簿 .xls格式文件）</div>
                    <input id="fileCover" class="left" readonly="readonly" placeholder="导入excel文件" type="text" style="width: 280px; height: 22px;">
                    <button onclick="$('#uploadFile').click();return false;" style="background: #aaa">浏览文件</button>
                    <input type="file" name="uploadFile" required="required" id="uploadFile" style="display:none" onchange="$('#fileCover').val($(this).val());">
                    <div>
                        <button type="submit" style="display: block; margin: 0 auto;">提交</button> 
                    </div>
                </form>
            </div>
            <div class="pannel hide" id="major-modal-1">
                <div>
                    <div class="close-container">
                        <a class="close" onclick="hide('#mask, #above-mask, #major-modal-1')">&times;</a>
                    </div>
                    <form action="${path}/adminmajmanage/submit" method="post">
                        <table>
                            <tr>
                                <td>专业编号</td>
                                <td><input type="text" placeholder="必填" name="major.majorNo" required="required"></td>
                            </tr>
                            <tr>
                                <td>专业名称</td>
                                <td><input type="text" placeholder="必填" name="major.majorName" required="required"></td>
                            </tr>
                            <tr>
                                <td>所属学院</td>
                                <td>
                                    <#if collegeCode?exists>
                                    <select name="major.collegeCode">
                                        <#list collegeCode as cc>
                                        <option value="${cc.collegeCode}">${cc.collegeCode}-${cc.collegeName}</option>
                                        </#list>
                                    </select>
                                    </#if>
                                </td>
                            </tr>
                            <tr><td colspan="2"><button type="submit">提交</button></td></tr>
                        </table>
                    </form>		
                </div>
            </div>

            <div class="pannel hide" id="major-modal-2">
                <div>
                    <div class="close-container">
                        <a class="close" onclick="hide('#mask, #above-mask, #major-modal-2')">&times;</a>
                    </div>
                    <form action="${path}/adminmajmanage/update" method="post">
                        <table class="table table-bordered" id="majortable2">
                            <tr>
                                <td>专业编号</td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>专业名称</td>
                                <td><input type="text" id="majorName" name="major.majorName" placeholder="必填" value=""></td>
                            </tr>
                            <tr>
                                <td>所属学院</td>
                                <td>
                                    <#if collegeCode?exists>
                                    <select name="major.collegeCode" id="collegeCode">
                                        <#list collegeCode as cc>
                                        <option value="${cc.collegeCode}">${cc.collegeCode}-${cc.collegeName}</option>
                                        </#list>
                                    </select>
                                    </#if>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <input type="hidden" id="id" name="major.id" value="">
                                    <input type="hidden" id="majorNo" name="major.majorNo" value="">
                                    <button type="button" onclick="ajaxupdate(); hide('#mask, #above-mask, #major-modal-2')">确定</button>
                                </td>
                            </tr>
                        </table>	
                    </form>
                </div>
            </div>
        </div>
        <div id="mask"></div>
        <!--header-->
        <div id="header"></div>
        <div id="main">
            <div id="side-menu"></div>
            <div id="container">
                <div id="inner-border">
                    <button onclick="window.location.href = '${path}/adminmajmanage/fileDownload'">模板下载</button>
                    <button onclick="show('#mask, #above-mask, #fileupload-pannel')">批量导入</button>
                    <button onclick="window.location.href='${path}/proinfExport/exportExcel'">批量导出</button>
                    <button onclick="show('#mask, #above-mask, #major-modal-1')">新增专业</button>
                    <!-- <div>
                        <select id="keyword" name="keyword">
                            <option value="all">全部</option>
                            <#if college?exists>
                            <#list college as c>
                            <option value="${c.collegeCode}">${c.collegeCode}</option>
                            </#list>
                            </#if>
                        </select>
                        <button onclick="ajaxsearch()">筛选</button>	
                    </div> -->
                    <form action="${path}/adminmajmanage/batch" >
                        <input type="hidden" name="checkboxValue" id="checkboxValue">
                        <div id="error" style="display:none">${error!}</div>
                        <table id="majortable">
                            <thead>
                                <tr>
                                    <th>&nbsp;&nbsp;&nbsp;</th>
                                    <th>专业编号</th>
                                    <th>专业名称</th>
                                    <th>学院名称</th>
                                    <th>操作</th>
                                </tr> 
                            </thead>
                            <tbody id="mtbody">
                                <#if major?exists>
                                <#list major as m> 
                                <tr>
                                    <td><input type="checkbox" value="${m.id}" name="majCheckbox" id="majCheckbox" ></td>
                                    <td name="majors">${m.majorNo}</td>
                                    <td name="majors">${m.majorName}</td>
                                    <td name="majors">${m.collegeName}</td>
                                    <td><button name="editBtn" class="edit" onclick="edit(this); show('#mask, #above-mask, #major-modal-2');return false;">编辑</button></td>
                                </tr>
                                </#list>
                                </#if>
                            </tbody>
                        </table>
                        <button class="delete" type="submit" onclick="getParam('majortable', 'checkboxValue');">删除</button>
                    </form>
                </div>
            </div>
        </div>
                <div id="footer"></div>
        <script type="text/javascript" src="${path}/js/admin-main-appearance.js"></script>
        <!--        <script src="${path}/js/app.js"></script>
                <script src="${path}/js/fc.js"></script>-->

        <!-- DataTables JavaScript -->
        <script src="${path}/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetHiddenNodes.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTd.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTds.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetColumnData.js"></script>
        <script src="${path}/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
        <!-- End DataTables JavaScript -->
        <script src="${path}/js/linkPage.js"></script>
        <script type="text/javascript">
                            var row;
                            function edit(node) {
                                var tr1 = node.parentNode.parentNode;
                                document.getElementById('majortable2').rows[0].cells[1].innerHTML = tr1.cells[1].innerHTML;
                                document.getElementById('majorName').value = tr1.cells[2].innerHTML;
                                document.getElementById('collegeCode').value = tr1.cells[3].innerHTML;
                                document.getElementById('id').value = tr1.cells[0].children[0].value;
                                document.getElementById('majorNo').value = tr1.cells[1].innerHTML;
                                row = tr1.rowIndex;
                                return row;
                            }
                            function ajaxupdate() {
                                $.ajax({
                                    type: "post",
                                    url: '${path}/adminmajmanage/ajaxupdate',
                                    data: {
                                        majorName: $('#majorName').val(),
                                        collegeCode: $('#collegeCode').val(),
                                        id: $('#id').val(),
                                        majorNo: $('#majorNo').val(),
                                    },
                                    datatype: "json",
                                    success: function (data) {
                                    //alert(JSON.stringify(data));
                                        document.getElementById('majortable').rows[row].cells[2].innerHTML = data.major[0]["majorName"];
                                        document.getElementById('majortable').rows[row].cells[3].innerHTML = data.major[0]["collegeName"];
                                        alert(data.error);
                                    }
                                });
                            }
        </script>
        <script type="text/javascript">
            function ajaxsearch() {
                $.ajax({
                    type: "post",
                    url: '${path}/adminmajmanage/ajaxsearch',
                    data: {
                        keyword: $('#keyword').val(),
                    },
                    datatype: "json",
                    success: function (data) {
                        $(document).ready(function () {
                            $('#majortable').dataTable().fnClearTable();
                            for (var i = 0; i < data.length; i++) {
                                $('#majortable').dataTable().fnAddData(['<input type="checkbox" value="' + data[i]["id"] + '" name="majCheckbox" id="majCheckbox" >', data[i]["majorNo"], data[i]["majorName"], data[i]["collegeCode"], '<button name="editBtn" class="edit" class="edit" onclick="edit(this); show(\'#mask, #above-mask, #major-modal-2\');return false;">编辑</button>']);
                                var id = data[i]["id"];
                                //alert(id);
                                var ot = $('#majortable').dataTable();
                            }
                        });
                    }

                });
            }
        </script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#majortable').DataTable({
                    responsive: true,
                    ordering: false,
                    searching: true,
                    "bLengthChange": false,
                    "bRetrieve": true,
                    "bFilter": true//过滤功能
                });
            });
        </script>
        <script type="text/javascript">
            $(document).ready(function () {
                if ($("#error").html() != "") {
                    Alert($("#error").html());
                }
                //alert($("#error").html());}
            });
        </script> 
        <script>
            //自动关闭提示框  
            function Alert(str) {
                alert(str);
            }
        </script>
    </body>
</html>
